package toman;

import java.util.List;

/**
 * This interface represents a generalized query created by TOMan. It is returned by TOMan's <code>createQuery</code> method.
 * <br>
 * User: zslajchrt
 * Date: 2.5.11
 * Time: 16:05
 */
public interface TOQuery<T> extends ParameterizedQuery {

    /**
     * Sets the start index in the underlying result list from where the returned list will start.
     * @param index the start index pointing to the underlying list.
     * @return this object
     */
    TOQuery setFirstResult(int index);

    /**
     * Sets the maximal number of elements in the result list.
     * @param max the maximal number of elements
     * @return this object
     */
    TOQuery setMaxResults(int max);

    /**
     * @return the list of result to the query
     */
    List<T> getResults();

    /**
     * @return the single result raw data object or there is no result for this query
     * @throws NonUniqueResultException if there is more than one result for this query
     */
    T getSingleResult();

    /**
     * @return the wrapped (internal) query or null
     */
    Object getInternalQuery();

    class NonUniqueResultException extends RuntimeException {
        private static final long serialVersionUID = -5744359454265286767L;

        public NonUniqueResultException(String message, Throwable cause) {
            super(message, cause);
        }
    }

}
